/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RENDER_OBJ_FRAME_HH
#define RENDER_OBJ_FRAME_HH
//! \addtogroup introsight_framework
//@{

// INCLUDES
#include "render_obj.hh"
#include "render_attr.hh"

// DEFINES
#define ROF_MAX_KEYNAME   15

class render_mng;
class render_stats;

class render_obj_frame: public render_obj
{
    // viewport definition
    float view[IS_WXYWH];
    bool view_percentage[IS_WXYWH];
    int viewport[IS_WXYWH];
    float aspect;

    // some precalcs
    float pixel[IS_WXY];     // pixel size in viewport coordinates
    float stat_box_precalcs[IS_WXYWH<<1];
    float help_box_precalcs[IS_WXYWH+IS_2D];

    // clear frame
    bool clear;
    render_color_anim clear_color;
    unsigned char clear_color_nonselect[IS_RGBA];
    unsigned char clear_color_select[IS_RGBA];
    unsigned char clear_color_cselect[IS_RGBA];
    unsigned clear_color_anim_usec;

    // render statistics
    render_stats *stats;
    float stats_title_color[IS_RGBA];
    float stats_value_color[IS_RGBA];
    float stats_box_color[IS_RGBA];
    float stats_box_position[IS_WXY];

    // cursor
    bool cursor;
    float cursor_color[IS_RGBA];

    // help
    bool help;
    struct help_structure
    {
	unsigned short key_code, key_status;
	char key_name[ROF_MAX_KEYNAME];
	const char *tip;
    };
    help_structure *help_str;
    int n_help_str, max_help_str;
    render_obj *help_obj;
    unsigned help_selector, help_action;
    int help_coord[IS_2D];
    int help_max_key, help_max_tip;
    float help_tip_color[IS_RGBA];
    float help_key_color[IS_RGBA];
    float help_box_color[IS_RGBA];

    // PRIVATE METHODS
    void ctor();
    void dtor();

    // custom render functions
    void render_clear();
    void render_clear_select();
    void render_calculate_viewport(render_mng *ctx);
    void render_calculate_precalcs(render_mng *ctx);
    void render_params_common(); // returns true if require refresh
    void render_params_opaque();
    void render_perspective();
    void render_perspective_selection(render_mng *ctx);
    void render_statistics(render_mng *ctx);
    void render_statistics_select(render_mng *ctx);
    void render_cursor(int x, int y, unsigned type);
    void render_help(render_mng *ctx, int x, int y);

    // actions
    bool action_dispatcher(render_mng *ctx, unsigned type, unsigned event);

public:
    render_obj_frame();
    virtual ~render_obj_frame();

    virtual bool init(render_mng *ctx);
    virtual void render(render_mng *ctx);
    virtual bool event(render_mng *ctx);
    virtual unsigned get_type();           // returns IS_TYPE_*

    // stats
    void stats_activate();
    void stats_deactivate();

    // getters
    inline int get_viewport(int i) {return viewport[i];}
    inline float get_aspect() {return aspect;}
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	render_obj_frame
	{
		# members
		view, view_percentage,
		clear, clear_color,
		clear_color_nonselect,
		clear_color_select,
		clear_color_cselect,
		clear_color_anim_usec,
		stats_title_color,
		stats_value_color,
		stats_box_color,
		stats_box_position,
		cursor,
		cursor_color,
		stats,
		help,
		help_tip_color,
		help_key_color,
		help_box_color:
						select

		# methods
		init, render,
		stats_activate,
		stats_deactivate:
						select
	}
   )
*/
